<?php

	class UrlRoutingToPageCommand implements ICommand
	{
		function execute($event)
		{
			$route 	= $event->data;
			$module = $route->data["module"];
			$file 	= $route->data["file"];
			$pModel	= EbModel::getModel('Core','Page');
			$page	= $pModel->selectByUr_id($route->ur_id);
			
			if (isset($route->data['theme']))
			{
				EbView::$skin = $route->data['theme'];
			}			
			
			if (isset($route->data['skin']))
			{
				EbView::$skin = $route->data['skin'];
			}
			
			EbView::setFragment("content", $module."/".$file);

			$buffer = EbView::renderHtml();
		
			EbController::$response->type = EbResponse::HTML;
			EbController::$response->content = $buffer;
			
			return true;			
						
			if ($this->securityTest($route))
			{			
				EbView::setFragment("content", $module."/".$file);
	
				$buffer = EbView::renderHtml();
			
				EbController::$response->type = EbResponse::HTML;
				EbController::$response->content = $buffer;
				
				return true;
			}
			else
			{
				return new Event('redirect','/login?ref='.EbController::$request->url);
			}
		}
		
		protected function securityTest($url)
		{
			$rr = $url->roles;
						
			if ($rr == "" || $rr == 1)
			{
				return true;
			}
			else
			{
				$session = EbController::$session;
								
				if (Community_BasicUser::hasRole($rr))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			
		}		
	}